package com.算法.dispose;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * <p>
 *
 * </p>
 *
 * @author zh
 * @date 2024-05-29 00:35
 */
public class Dispose {
    public static void main(String[] args) {
        detect();
    }
    public static String detect() {
        // 异步执行视频流处理
        new Thread(() -> {
            // C:\Users\朱鹏\Desktop\test\worker
            String workingDirectory = "C:\\Users\\朱鹏\\Desktop\\test\\worker";
            String pythonEnvCommand = "D:\\Program Files (x86)\\Python\\Python";
            String pythonScriptCommand = "python ConstructionSafetyVideo.py";
            try {
                // 创建ProcessBuilder对象
                ProcessBuilder pb = new ProcessBuilder("D:\\Program Files (x86)\\Python\\Python\\python", "D:\\work\\worker\\ConstructionSafetyVideo.py");
                // 启动进程并等待其完成
                Process process = pb.start();
                int exitCode = process.waitFor();
                BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
                String errorLine;
                while ((errorLine = errorReader.readLine()) != null) {
                    System.err.println(errorLine);
                }
                // 读取并输出脚本执行结果
                BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
                String line;
                while ((line = reader.readLine()) != null) {
                    System.out.println(line);
                }
                if (exitCode == 0) {
                    System.out.println("Python脚本执行成功");
                } else {
                    System.err.println("Python脚本执行失败");
                }
            } catch (IOException | InterruptedException e) {
                e.printStackTrace();
            }
        }).start();
        return "";
    }
}
